package com.neuedu.io.serializable;

import java.io.Serializable;
import java.util.Date;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/3111:21
 *
 *
 * 序列化 文件之后 改动了 class ，再次读取 会报错
 * Caused by: java.io.InvalidClassException: com.neuedu.io.serializable.User; local class incompatible: stream classdesc serialVersionUID = -7571637665674151596, local class serialVersionUID = 9086150823461272973
 */
public class User implements Serializable {


    //保证序列化 和返序列化中间 class 发生变化的时候  认为是同一个class
    public static final long serialVersionUID = -7571637665674151596l;

    private String username;


    /***
     * 敏感的信息不应该  序列化
     * transient 不需要返序列化
     */
    private transient String password;
    private Date expireDate;


    public User(String username, String password, Date expireDate) {
        this.username = username;
        this.password = password;
        this.expireDate = expireDate;
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", expireDate=" + expireDate +
                '}';
    }
}
